package com.example.javafx.文本域;

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * 将字符串值从TextField绑定到Stage Title。
 *
 */
public class Main_2 extends Application {

    StringProperty title = new SimpleStringProperty();

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        TextField titleTextField;
        titleTextField = new TextField();
        titleTextField.setText("Search Coache");
        titleTextField.setPrefColumnCount(15);

        HBox hBox = new HBox();
        hBox.setSpacing(10);
        hBox.getChildren().add(new Label("title:"));
        hBox.getChildren().add(titleTextField);

        Scene scene = new Scene(hBox,270,270);
        title.bind(titleTextField.textProperty());

        primaryStage.setScene(scene);
        primaryStage.titleProperty().bind(title);

        primaryStage.show();
    }
}
